﻿using FarseerPhysics.Dynamics;
using Microsoft.Xna.Framework;

namespace IcicleFramework.Components.Physics
{
    public class SingleBodyPhysicsComponent : PhysicsComponent
    {
        public SingleBodyPhysicsComponent() {}

        public SingleBodyPhysicsComponent(SingleBodyPhysicsComponent old)
            : base(old) {}

        public override Body GetPrimaryBody()
        {
            if (NumBodies > 0)
                return GetFirstBody();
            
            return null;
        }

        public override void ApplyImpulse(Vector2 impulse, string name)
        {
            base.ApplyImpulse(impulse);
        }
        
        /*public override void Deserialize(XElement element)
        {
            IPhysicsManager physicsManager = GameService.GetService<IPhysicsManager>();
            
            if (physicsManager != null && element != null)
            {
                //Read in the body (and associated shape/fixture)
                if (element.Element("body") != null)
                {
                    Body body = FarseerDeserialization.DeserializeBody(element.Element("body"), physicsManager, Parent);

                    //By default this body has to be the primary body since it's the only one!
                    FarseerUserData userData = (FarseerUserData) body.UserData;
                    userData.Primary = true;
                    Bodies.Add(userData.Name, body);
                }

                //A single-body physics component only supports joints that require only a single body (for obvious reasons...)
                //But we'll expect the FarseerDeserialization class to handle any user error with this.
                if (element.Element("joints") != null)
                    this.Joints = FarseerDeserialization.DeserializeJoints(Parent, element.Element("joints"), physicsManager);
            }
        }*/

        public override IBaseComponent DeepClone()
        {
            return new SingleBodyPhysicsComponent(this);
        }
    }
}
